package com.yunhai.web.controller.file;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunhai.common.annotation.Log;
import com.yunhai.common.core.controller.BaseController;
import com.yunhai.common.core.domain.AjaxResult;
import com.yunhai.common.enums.BusinessType;
import com.yunhai.system.domain.InvestorRelation;
import com.yunhai.system.service.IInvestorRelationService;
import com.yunhai.common.utils.poi.ExcelUtil;
import com.yunhai.common.core.page.TableDataInfo;

/**
 * 投资者关系Controller
 *
 * @author jxj
 * @date 2021-01-21
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/file/relation")
public class InvestorRelationController extends BaseController {

    private final IInvestorRelationService investorRelationService;

    /**
     * 查询投资者关系列表
     */
    @PreAuthorize("@ss.hasPermi('file:relation:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvestorRelation investorRelation) {
        startPage();
        List<InvestorRelation> list = investorRelationService.queryList(investorRelation);
        return getDataTable(list);
    }

    /**
     * 导出投资者关系列表
     */
    @PreAuthorize("@ss.hasPermi('file:relation:export')")
    @Log(title = "投资者关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InvestorRelation investorRelation) {
        List<InvestorRelation> list = investorRelationService.queryList(investorRelation);
        ExcelUtil<InvestorRelation> util = new ExcelUtil<InvestorRelation>(InvestorRelation.class);
        return util.exportExcel(list, "relation");
    }

    /**
     * 获取投资者关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('file:relation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(investorRelationService.getById(id));
    }

    /**
     * 新增投资者关系
     */
    @PreAuthorize("@ss.hasPermi('file:relation:add')")
    @Log(title = "投资者关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvestorRelation investorRelation) {
        return toAjax(investorRelationService.save(investorRelation) ? 1 : 0);
    }

    /**
     * 修改投资者关系
     */
    @PreAuthorize("@ss.hasPermi('file:relation:edit')")
    @Log(title = "投资者关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvestorRelation investorRelation) {
        return toAjax(investorRelationService.updateById(investorRelation) ? 1 : 0);
    }

    /**
     * 删除投资者关系
     */
    @PreAuthorize("@ss.hasPermi('file:relation:remove')")
    @Log(title = "投资者关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(investorRelationService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
